package com.qiangesoft.blog.controller.manage;

import cn.dev33.satoken.stp.StpUtil;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.system.authentication.LoginService;
import com.qiangesoft.blog.system.pojo.dto.LoginDTO;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 登录 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@Api(tags = "登录-接口")
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @PostMapping("/login")
    public String login(@Validated @RequestBody LoginDTO vo) {
        return loginService.login(vo);
    }

    @PostMapping("/logout")
    public ResponseResult logout() {
        StpUtil.logout();
        return ResponseResult.success("退出成功");
    }
}
